home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 8.8 KB | 329 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UTheDebugger.cp
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UTHEDEBUGGER__
- #include "UTheDebugger.h"
- #endif
-
- // MacApp
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- #ifndef __UCOREUTILITIES__
- #include "UCoreUtilities.h"
- #endif
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
-
- #if qDebug || qTheDebugger
-
- static Boolean TheDbgr_CallBack();
-
- #endif
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- #if qTheDebugger
-
- //========================================================================================
- // Support for Jasik's The Debugger
- //========================================================================================
-
- T_ExtDbgr gExtDbgr_Info; // define struct block for Jasik Dbgr
-
- const long c_MA_Objs = 512; // obj list collector increment size
-
-
- //----------------------------------------------------------------------------------------
- // TheDbgr_Add_Object:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- void TheDbgr_Add_Object(TObject* objHdl)
- {
- long i,si;
- T_ObjList* obj_list;
-
- if( !gExtDbgr_Info.hMA_OBJ_List ) return;
-
- lp: {
- obj_list = *gExtDbgr_Info.hMA_OBJ_List;
- if( obj_list->L_used == obj_list->max_objs )
- {
- if( obj_list->n_holes > 0 ) // squeeze out empty entries
- {
- obj_list->n_holes = 0;
- si = 0;
- for(i = 0; i < obj_list->L_used; i++ )
- if( obj_list->objs[i] != 0 )
- {
- obj_list->objs[si++] = obj_list->objs[i];
- }
- obj_list->L_used = si;
- }
- else
- {
- obj_list->max_objs = obj_list->max_objs + c_MA_Objs;
- SetHandleSize((Handle)gExtDbgr_Info.hMA_OBJ_List, 12 + 4*obj_list->max_objs );
- obj_list = *gExtDbgr_Info.hMA_OBJ_List;
- if (MemError() != noErr) {
- DebugStr((StringPtr)"\pObject Collector could NOT get space to expand OBJ List");
- return;
- };
- goto lp;
- }
-
- }
- obj_list->objs[obj_list->L_used] = objHdl;
- obj_list->L_used++;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TheDbgr_Delete_Object:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- void TheDbgr_Delete_Object(TObject* objHdl)
- {
- long i;
- T_ObjList* obj_list;
-
- if( gExtDbgr_Info.hMA_OBJ_List )
- {
- obj_list = *gExtDbgr_Info.hMA_OBJ_List;
-
- for(i = 0; i < obj_list->L_used; i++ )
- if( obj_list->objs[i] == objHdl )
- {
- if( i == obj_list->L_used - 1 )
- {
- obj_list->L_used--;
- }
- else
- {
- obj_list->objs[i] = 0; obj_list->n_holes++;
- }
- return;
- }
- DebugStr((StringPtr)"\pTheDbgr_Delete_Object - Object not found");
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TheDbgr_CallBack:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- Boolean TheDbgr_CallBack()
- {
- long ConsWR_Proc;
-
- #if defined(powerc) || defined (__powerc)
-
- short proc_code[] = { // adj stk and Call Dbgr
- 0x201F, // move.l (SP)+,D0 ; rtn addr
- 0x4267, // CLR -(SP) ; setup Excpt stk frame
- 0x2F00, // move.l D0,-(SP)
- 0x4267, // CLR -(SP)
- 0x7007, // MOVEQ #7,D0 - isDbgrTask code
- 0x2078, 0x009C, // MOVE.L 4*(32+7),A0 ; trap #7 Handler addr
- 0x4ED0 // JMP (A0)
- };
-
- enum {
- TD_ProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Ptr)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Ptr)))
- };
- Boolean rtnVal;
- UniversalProcPtr upp = NewRoutineDescriptor((ProcPtr)proc_code , TD_ProcInfo , kM68kISA );
-
- rtnVal = CallUniversalProc(upp,TD_ProcInfo,&gExtDbgr_Info,&ConsWR_Proc);
- DisposeRoutineDescriptor(upp);
- return( rtnVal );
- #else
- return( TheDbgr_IsDbgrTask(&gExtDbgr_Info,&ConsWR_Proc) );
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // TheDbgr_Init_Ext_Dbgr:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- void TheDbgr_Init_Ext_Dbgr()
- {
- // initialize remaining fields in gExtDbgr_Info:
- // note that n_classes and pOrderedClass have already
- // been set in ClassDesc::InitUClassDesc; all other
- // fields were zeroed at global initialization time…
- gExtDbgr_Info.isBeingDebugged = FALSE;
- gExtDbgr_Info.MA_Version = 3;
-
- if( TheDbgr_CallBack() )
- {
- gExtDbgr_Info.isBeingDebugged = TRUE;
-
- // allocate space for an Object collection LIst
-
- gExtDbgr_Info.hMA_OBJ_List = (T_ObjList**) NewHandleClear((3*sizeof(long))+(c_MA_Objs*sizeof(TObject*)));
-
- if( gExtDbgr_Info.hMA_OBJ_List )
- {
- (**gExtDbgr_Info.hMA_OBJ_List).max_objs = c_MA_Objs;
- }
- }
- }
-
- // code to sort the class Descriptors so that the Class ID's have the property
- // that TObject is 1st and the class ID of a subclass > class ID of parent
-
- //----------------------------------------------------------------------------------------
- // sort4:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- static void sort4(long * v, short n) // Shell Sort from H & S 2nd Edition
- {
- short gap,i,j;
- long temp;
- gap = 1;
- do ( gap = 3*gap+1); while (gap <= n);
- for( gap /= 3; gap > 0; gap /= 3 )
- {
- for( i = gap; i < n; i++ )
- {
- temp = v[i];
- for( j = i-gap; (j >= 0) && (v[j] > temp); j -= gap)
- v[j+gap] = v[j];
- v[j+gap] = temp;
- }
- }
- }
-
- typedef struct T_cl_Sort
- {
- short Cl_ID;
- short subCl_ID;
- };
-
- static ClassDesc** pCL_AT; // ptr to the array
- static short* pCL_IT;
- static T_cl_Sort* psubc_IT = NULL;
-
- //static short g_Lvl = 0;
-
- //----------------------------------------------------------------------------------------
- // follow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- static void follow(short f_id)
- {
- static short new_CL_ID = 0;
-
- ClassDesc* pCD = pCL_AT[f_id];
- if( pCD )
- {
- pCL_AT[f_id] = 0;
- pCD->SetClassID(++new_CL_ID); // assign a new Class ID
-
- short indx = pCL_IT[f_id]; // index to sub class List
- //g_Lvl = g_Lvl + 1;
- while( (indx >= 0) && (psubc_IT[indx].Cl_ID == f_id) )
- {
- follow( psubc_IT[indx].subCl_ID );
- indx--;
- }
- //g_Lvl = g_Lvl + 1; // •• TWB •• probably should be -1
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TheDbgr_Adjust_ClassDescr_Ids:
- //----------------------------------------------------------------------------------------
- #pragma segment MADebugger
-
- void TheDbgr_Adjust_ClassDescr_Ids(ClassDesc* pclassList, short numClasses)
- {
- numClasses++; // for safety
- pCL_IT = (short*) NewPtrClear(sizeof(short) * numClasses); // point to arrays that follow accesses
- psubc_IT = (T_cl_Sort*) NewPtrClear(sizeof(T_cl_Sort) * numClasses);
- pCL_AT = (ClassDesc**) NewPtrClear(sizeof(ClassDesc*) * numClasses);
-
- short *CL_objNum = (short*) NewPtrClear(sizeof(short) * numClasses); // < FIX
-
- if (pCL_IT && psubc_IT && pCL_AT) // check our allocations
- {
- short i;
- short n_cl = 0;
- short n_objNum = 0; // <== FIX
- short CL_Tobj = 0;
-
- ClassDesc* pCD = pclassList;
- while( pCD )
- {
- psubc_IT[n_cl].subCl_ID = i = pCD->GetClassID(); // id of this class is sub Class ID
- pCL_AT[i] = pCD;
- if( pCD->CountBaseClasses() > 0 ) // MacApp 3.3 can't do GetBaseClass(1) if the count is 0
- {
- const ClassDesc* pBC = pCD->GetBaseClass(1);
- psubc_IT[n_cl].Cl_ID = pBC->GetClassID();
- }
- else
- {
- if (pCD == TObject::GetClassDescStatic())
- CL_Tobj = i;
- else // <== FIX
- CL_objNum[n_objNum++] = i; // <== FIX
-
- psubc_IT[n_cl].Cl_ID = 0;
- }
- pCD = (ClassDesc*) pCD->GetNextClassDesc(); // const cast away
- n_cl++;
- }
-
- sort4( (long *) &(psubc_IT[0]) , n_cl );
- psubc_IT[n_cl].Cl_ID = -1; // terminator for loop in follow
-
- for( i = 0; i <= n_cl; i++ ) pCL_IT[i] = 0;
-
- short last_cl = psubc_IT[0].Cl_ID;
- for ( i = 0; i <= n_cl; i++ )
- {
- short j = psubc_IT[i].Cl_ID;
- if( j != last_cl )
- {
- pCL_IT[last_cl] = i - 1;
- last_cl = j;
- }
- }
- follow(CL_Tobj);
- for ( i = 0; i < n_objNum; i++) follow(CL_objNum[i]); // <== FIX
- }
-
- DisposeIfPtr((Ptr)pCL_IT); // point to arrays that follow accesses
- DisposeIfPtr((Ptr)psubc_IT);
- DisposeIfPtr((Ptr)pCL_AT);
- DisposeIfPtr((Ptr)CL_objNum); // <== FIX
- }
-
- #endif // #if qTheDebugger
-
- //----------------------------------------------------------------------------------------
- // End of UTheDebugger.cp
-
- #pragma segment Inline
-